package Frame;

import java.awt.BorderLayout;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.util.ArrayList;

import javax.swing.BorderFactory;
import javax.swing.JButton;
import javax.swing.JLabel;
import javax.swing.JOptionPane;
import javax.swing.JPanel;
import javax.swing.JScrollPane;
import javax.swing.JSplitPane;
import javax.swing.JTable;
import javax.swing.JTextField;









import com.hankcs.hanlp.HanLP;

import CheckFile.CheckFile;
import Dao.DaoSqlData;
import Rank.insertIntoCustomDictionary;
import Rank.outPutRankText;
import Rule.FileChooserFilter;
import Rule.NameTag;
import Table.GetCommonTableAllValues;
import Table.MyTable;

public class ManagerImportPanel extends JPanel{
	
    static JScrollPane scrollPane;
	private static JTextField tfFilePath;
	private static JButton button_Show;
	private static JButton button_Open;
	
	public ManagerImportPanel(){
		
		scrollPane=new JScrollPane(); 
		scrollPane.setBorder(BorderFactory.createTitledBorder(NameTag.common_Tittle_2));
		
		JPanel panel_1 = new JPanel();
		JLabel label_1 = new JLabel(NameTag.common_File);
		tfFilePath = new JTextField("",20);
		tfFilePath.setEditable(false);		
		button_Show = new JButton(NameTag.show_1);
		button_Show.addActionListener(new ButtonListener());
		button_Open = new JButton(NameTag.Import_1);
		button_Open.addActionListener(new ButtonListener());

		panel_1.add(label_1);
		panel_1.add(tfFilePath);
		panel_1.add(button_Show);
		panel_1.add(button_Open);
		this.setLayout(new BorderLayout());	
		this.add(panel_1, BorderLayout.NORTH);
		this.add(scrollPane, BorderLayout.CENTER);		
	}
	
	
	private static class ButtonListener implements ActionListener{
			
		private static  JTable mytable;
		@Override
		public void actionPerformed(ActionEvent e) {
			
				if(e.getSource() == button_Show ){
					
					String sFilePath = FileChooserFilter.ExcelFilter(tfFilePath);
					if(sFilePath == null ){return;}
					mytable = MyTable.getTable(sFilePath);	
					scrollPane.setViewportView(mytable);				
				}	
				else if(e.getSource() == button_Open){
					
					if(mytable == null){return;}
					ArrayList<String> values = GetCommonTableAllValues.GetAllValues(mytable);
					int SuccessImportCount = DaoSqlData.setPrdInfo_multi(values);
					JOptionPane.showMessageDialog(null, "成功导入"+ SuccessImportCount +"条数据");
					mytable = null;
					scrollPane.updateUI();
					tfFilePath.setText("");
				}
		}	
	}
		
}
